
from rest_framework.generics import ListAPIView
from django.core.cache import cache
from rest_framework.response import Response
from . import models
from . import serializers
from django.conf import settings

class Banner(ListAPIView):

    queryset = models.Banner.objects.filter(is_delete=False, is_show=True).order_by('-order')[:settings.BANNER_COUNT]
    serializer_class = serializers.BannerModleSerializer

    def list(self, request, *args, **kwargs):
        banner_ls = cache.get('Banner_ls')
        if banner_ls is not None:
            return Response(banner_ls)
        banner_response = super(Banner, self).list(request, *args, **kwargs)
        cache.set('Banner_ls', banner_response.data, None)
        return banner_response



